using System.Collections.Generic;
using UnityEngine;

namespace Gj
{
    public static class FormationTools
    {
        private static readonly Dictionary<string, Vector2[]> map;

        static FormationTools()
        {
            var settings = LoadSettings();
            map = new Dictionary<string, Vector2[]>();
            for (var i = 0; i < settings.formationItems.Length; i++)
                map.Add(settings.formationItems[i].key, settings.formationItems[i].values);
        }

        private static FormationSettings LoadSettings()
        {
            var loadedSettings = (FormationSettings)Resources.Load("FormationSettings", typeof(FormationSettings));
            if (loadedSettings == null)
            {
                loadedSettings = ScriptableObject.CreateInstance<FormationSettings>();
                Debug.LogError("ReplaceSettings is not exist (Resources)");
            }

            return loadedSettings;
        }

        public static Vector2[] Get(int key, float radius)
        {
            var list = new Vector2[0];
            var nk = key.ToString();
            if (map.ContainsKey(nk))
            {
                list = new Vector2[map[nk].Length];
                for (var i = 0; i < map[nk].Length; i++)
                {
                    list[i] = map[nk][i];
                    list[i].x *= radius;
                    list[i].y *= radius;
                }
            }

            return list;
        }
    }
}